package com.rabbit.rabbitmqspringboot.controller;


import com.rabbit.rabbitmqspringboot.constant.Constants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/pro")
@RestController
public class ProdueController {

    @Autowired
    private RabbitTemplate rabbitTemplate;     // 这里相当于 创建了连接，并且建立了信道

    // 通过 web 来发送消息

    // 工作模式
    @RequestMapping("work")
    public String work(){
        rabbitTemplate.convertAndSend("", Constants.WORK_QUEUE,"hello ,I'm work mode");
        return "work 模式 消息：发送成功";
    }

    //订阅模式
    @RequestMapping("/fanout")
    public String fanout(){
        rabbitTemplate.convertAndSend(Constants.FANOUT_EXCHANGE,""," hello ,I'm fanout mode");
        return "fanout 模式 消息：发送成功";
    }

    // 路由模式
    @RequestMapping("/direct")
    public String direct(){
        rabbitTemplate.convertAndSend(Constants.DIRECT_EXCHANGE,"a"," hello ,I'm direct mode : a");
        rabbitTemplate.convertAndSend(Constants.DIRECT_EXCHANGE,"b"," hello ,I'm direct mode : b");
        rabbitTemplate.convertAndSend(Constants.DIRECT_EXCHANGE,"c"," hello ,I'm direct mode : c");
        return "fanout 模式 消息：发送成功";
    }

    // topic 模式
    @RequestMapping("/topic")
    public String topic(){
        rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE,"hello.a.b"," hello ,I'm topic mode： hello.a.b");
        rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE,"hello.b.rabbitmq"," hello ,I'm topic mode：hello.b.rabbitmq");
        rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE,"c.hello"," hello ,I'm topic mode：c.hello");
        rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE,"c.hello.rabbitmq"," hello ,I'm topic mode：c.hello.rabbitmq");
        return "topic 模式 消息 ： 发送成功";
    }
}
